# Maintainer: Patrick Stewart <patstew@gmail.com>

pkgbase=mingw-w64-python-pyzmq
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-pyzmq" "${MINGW_PACKAGE_PREFIX}-python3-pyzmq")
pkgver=15.2.0
pkgrel=1
pkgdesc="Python bindings for zeromq, written in Cython (mingw-w64)"
arch=('any')
url="http://www.zeromq.org/bindings:python"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-zeromq")

source=("https://pypi.python.org/packages/source/p/pyzmq/pyzmq-${pkgver}.tar.gz"
        "001-mingw-python.patch")
sha256sums=('2dafa322670a94e20283aba2a44b92134d425bd326419b68ad4db8d0831a26ec'
            'b9b642fc7939d53b456cca51195632109c711ebf173ff8fb418c84a05c1e7eac')
prepare() {
  cd "${srcdir}"
  patch -p1 -i ${srcdir}/001-mingw-python.patch
  cp -a pyzmq-${pkgver} py2zmq-${pkgver}
}

all_build() {
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/${1} setup.py install \
    --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1 --zmq=${MINGW_PREFIX}

  find "${pkgdir}/" -name "*.pyc" -delete
  find "${pkgdir}/" -type d -empty -delete
	
	rm -rf build
}

package_python3-pyzmq() {
  local interpreter=python3
  depends=("${MINGW_PACKAGE_PREFIX}-python3"
           "${MINGW_PACKAGE_PREFIX}-zeromq")

  cd "${srcdir}/pyzmq-${pkgver}"

  sed -i 's|except socket.error, e:|except socket.error as e:|' zmq/eventloop/ioloop.py
  sed -i 's|except gevent.Timeout, t:|except gevent.Timeout as t:|' zmq/green/core.py

  all_build ${interpreter}
}

package_python2-pyzmq() {
  local interpreter=python2
  depends=("${MINGW_PACKAGE_PREFIX}-python2"
           "${MINGW_PACKAGE_PREFIX}-zeromq")

  cd "${srcdir}/py2zmq-${pkgver}"

  rm -f ./buildutils/include_win32/stdint.h

  all_build ${interpreter}
}

package_mingw-w64-i686-python2-pyzmq() {
  package_python2-pyzmq
}

package_mingw-w64-i686-python3-pyzmq() {
  package_python3-pyzmq
}

package_mingw-w64-x86_64-python2-pyzmq() {
  package_python2-pyzmq
}

package_mingw-w64-x86_64-python3-pyzmq() {
  package_python3-pyzmq
}
